﻿@model IEnumerable<ETL.Business.Models.ProjectETRModel>
@{
    ViewBag.Title = "ETR";  
    
}
<style type="text/css">
    tr.clickable
    {
        cursor: pointer;
        background: #ffff99;
    }
    tr.selected
    {
        cursor: pointer;
        background: #ffff99 !important;
    }
</style>
<script type="text/javascript">

    /*  Get projectETR detailed information    */
    function GetETRDetail(etr_ref) {
        $.ajax({
            url: "/ETR/GetETRDetail/",
            type: 'POST',
            data: { etrRef: etr_ref },
            success: function (response) {
                //                // Split response to array of values
                var array = response.split("#");

                //                // Replace old values with new ones
                $("#AuthorisedBy").val(array[0]);
                $("#RequestedBy").val(array[1]);
                $("#DateRequired").val(array[2]);
                $("#Sheets").val(array[3]);
                if (array[4] == "True") {
                    $("#Reason").attr("checked", "checked")
                } else {
                    $("#Reason").removeAttr("checked")
                };
                $("#Complete").val(array[5]);
                $("#Reference").val(array[6]);
                $("#Reference").append(array[6]);
                $("#Elec").val(array[7]);
                $("#Elec_hour").val(array[8]);
                $("#Soft").val(array[9]);
                $("#Soft_hour").val(array[10]);
                $("#CAD").val(array[11]);
                $("#CAD_hour").val(array[12]);
                $("#Other").val(array[13]);
                $("#Other_hour").val(array[14]);
                $("#ETR_Des").val(array[15]);
                $("#ETR_Req").val(array[16]);

            },
            error: function (xhr) {
                alert(xhr);
            }
        });
    }

    function LogOnToEtr(etrRef) {
        $.ajax({
            url: "/ETR/LogOnToEtr/",
            type: 'POST',
            data: { etrRef: etrRef },
            success: function (response) {

            },
            error: function (xhr) {
                alert(xhr);
            }
        });
    }

    // highlight hovered row
    $(function () {
        //Disable all inputs
        $("input").attr("disabled", "disabled");
        $("input[type=checkbox]").attr("disabled", "disabled");
        $("textarea").attr("disabled", "disabled");

        $('table.GridETR tbody tr').on({
            click: function () {
                $('table.GridETR tbody tr').each(
                function () {
                    $(this).removeClass('selected');
                }
            );
                $(this).addClass('selected');

                var etr_ref = $(this).find('td:first').text();
                //alert(etr_ref);
                GetETRDetail(etr_ref);
            },
            dblclick: function () {

                $('table.GridETR tbody tr').each(
                function () {
                    $(this).removeClass('selected');
                }
            );
                $(this).addClass('selected');
                var etr_ref = $(this).find('td:first').text();
                LogOnToEtr(etr_ref);
            },
            mouseenter: function () { $(this).addClass("clickable"); },
            mouseleave: function () { $(this).removeClass("clickable"); }
        });
    });
 
</script>
<div class="ETR"> 
    <fieldset>
        <legend>Engineering Task Requests</legend>
        <form class="form-horizontal">
        <div class="mainETR row-fluid">
            <div class="span7">
                <p style="margin-left: 100px;">
                    Double click on an ETR to log onto the ETR</p>
                <div class="EtrList well">
                    @{
                        var gridETR = new WebGrid(
                            Model,
                            defaultSort: "Reference",
                            fieldNamePrefix: "gridETR_",
                            canSort: false,
                            canPage: false
                            );

                    }
                    @gridETR.GetHtml(
                            tableStyle: "GridETR table table-hover",
                            headerStyle: "webgrid-header",
                            footerStyle: "webgrid-footer",
                            alternatingRowStyle: "webgrid-alternating-row",
                            selectedRowStyle: "webgrid-selected-row",
                            rowStyle: "webgrid-row-style",
                                     columns: gridETR.Columns(
                                     gridETR.Column("Reference", "ETR Ref", @<text>@item.Reference</text>),
                                     gridETR.Column("Title", "Title", @<text>@item.Title</text>),
                                     gridETR.Column("Description", "Description", @<text>@item.Description</text>)

                            ))
                </div>
            </div>
            <div class="span5">
                <div class="control-group">
                    <label class="control-label" for="">
                        Authorised By</label>
                    <div class="controls">
                        <input id="AuthorisedBy" type="text" style="width: 160px;">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        Requested By</label>
                    <div class="controls">
                        <input id="RequestedBy" type="text" style="width: 160px;">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        Date Required</label>
                    <div class="controls">
                        <input id="DateRequired" type="text" style="width: 160px;">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        No of Sheets</label>
                    <div class="controls">
                        <input id="Sheets" type="text" style="width: 50px;">
                        Reason Required
                        <input id="Reason" type="checkbox">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        % Complete</label>
                    <div class="controls">
                        <div class="input-append">
                            <input id="Complete" type="text" style="width: 35px;">
                            <span class="add-on">%</span>
                        </div>
                        <input id="Reference" type="text" style="width: 80px; text-align: center; color: Green;
                            font-weight: bold">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        Electronics</label>
                    <div class="controls">
                        <input id="Elec" type="text" style="width: 90px;">
                        <div class="input-append">
                            <input id="Elec_hour" type="text" style="width: 50px;">
                            <span class="add-on">hours</span>
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        Software</label>
                    <div class="controls">
                        <input id="Soft" type="text" style="width: 90px;">
                        <div class="input-append">
                            <input id="Soft_hour" type="text" style="width: 50px;">
                            <span class="add-on">hours</span>
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        CAD</label>
                    <div class="controls">
                        <input id="CAD" type="text"  style="width: 90px;">
                        <div class="input-append">
                            <input id="CAD_hour" type="text" style="width: 50px;">
                            <span class="add-on">hours</span>
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="">
                        Others</label>
                    <div class="controls">
                        <input id="Other" type="text" style="width: 90px;">
                        <div class="input-append">
                            <input id="Other_hour" type="text" style="width: 50px;">
                            <span class="add-on">hours</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="descriptionETR row-fluid">
            <b>Description</b>
            <textarea id="ETR_Des" rows="50" cols="50"></textarea>
        </div>
        <div class="outputReq row-fluid">
            <b>Output Requirements</b>
            <textarea id="ETR_Req" rows="50" cols="50"></textarea>
        </div>
        <div class="row button-group">
            <button type="button" class="btn ">
                Close</button>
            <button type="button" id="btnReport" class="btn btn-success">
                Report</button>
        </div>
        </form>
    </fieldset>
</div>
@*@model IEnumerable<EngineerTimeLog_mvc4.Models.project_etr>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.etr_ref)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_title)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_description)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_requirements)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_authorised_by)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_requested_by)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_date_requested)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_date_required)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_originator)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_reason)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_others)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_created)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_closed)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_closed_by)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_electronics)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_electronics_hours)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_software)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_software_hours)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_cad)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_cad_hours)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_other)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_other_hours)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_sheets)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_rd)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_percent_complete)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_overhead)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_date_authorised)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_email_sent)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_rejected_by)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_rejection_reason)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_active)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etr_department)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.etr_ref)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_description)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_requirements)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_authorised_by)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_requested_by)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_date_requested)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_date_required)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_originator)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_reason)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_others)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_created)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_closed)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_closed_by)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_electronics)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_electronics_hours)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_software)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_software_hours)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_cad)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_cad_hours)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_other)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_other_hours)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_sheets)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_rd)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_percent_complete)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_overhead)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_date_authorised)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_email_sent)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_rejected_by)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_rejection_reason)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_active)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etr_department)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
        </td>
    </tr>
}

</table>
*@